package com.hfkh.keyun.controller.frontend;

import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.Major;
import com.hfkh.keyun.service.MajorService;
import com.hfkh.keyun.vo.MajorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/app/major")
@Api(tags = "专业管理")
public class MajorControllerApp {
    @Resource
    private MajorService majorService;

    @PostMapping("/deleteMajor")
    @ApiOperation("按id删除专业列表")
    public ApiResult deleteMajor(@RequestBody Integer id){
        majorService.removeById(id);
        return ApiResult.ok("删除成功！", "头像上传成功！");
    }

    @PostMapping("/addMajor")
    @ApiOperation("添加专业列表")
    public ApiResult addMajor(MajorVO majorVO){
        Major major = new Major();
        BeanUtils.copyProperties(majorVO,major);
        majorService.save(major);
        return ApiResult.ok("添加成功！", "头像上传成功！");
    }


    @GetMapping("/majorList")
    @ApiOperation("查询专业列表")
    public ApiResult<List<Major>> queryList(){
        Map<String ,Object> map=new HashMap<>();
        map.put("delete_flags",0);
        List<Major> carousels = majorService.listByMap(map);
        return ApiResult.success(carousels);
    }

    @GetMapping("/majorListById")
    @ApiOperation("根据id查询专业列表")
    public ApiResult majorListById(Integer id){
        Major major = majorService.getById(id);
        return ApiResult.success(major);
    }
}
